package com.tuangou.tuangoucomsumer.comsumer.controller;

import java.util.Arrays;
import java.util.Map;

import com.atguigu.common.utils.Des;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tuangou.tuangoucomsumer.comsumer.entity.UserEntity;
import com.tuangou.tuangoucomsumer.comsumer.service.UserService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * 
 *
 * @author zjb
 * @email zjb@tuangou.com
 * @date 2021-06-17 09:39:53
 */
@RestController
@RequestMapping("comsumer/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("comsumer:user:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    //@RequiresPermissions("comsumer:user:info")
    public R info(@RequestParam Integer userId){
		UserEntity user = userService.getById(userId);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("comsumer:user:save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("comsumer:user:update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("comsumer:user:delete")
    public R delete(@RequestBody Integer[] userIds){
		userService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

    /*
    * 邀请微信好友参团
    * 传商品id goodsId   和  团长id tzId
    * */
    @RequestMapping("/inviteFriends")
    public R inviteFriends(@RequestParam Integer goodsId,@RequestParam Integer tzId){
        //给商品id 和 团长id 加密
        String goodsEncryptjm = Des.encryptjm(goodsId + "", "3333555566667777");
        String tzEncryptjm1 = Des.encryptjm(tzId + "", "3333555566667777");
        //加密后的id和连接进行拼装
        String url = "http://localhost:8020/goods/goods/groupBooking?goodsId="+goodsEncryptjm+"&tzId="+tzEncryptjm1;
        log.info(url);
        return R.ok(url);
    }

}
